package co.chuangdian.oflauncher.setting;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import uc.CircleGallery;
import uc.VideoPlayActivity;
import co.chuangdian.oflauncher.OFActivity;
import co.chuangdian.oflauncher.R;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import cn.onekit.ASSET;

public class FeaturesActivity extends OFActivity {
	CircleGallery features_gallery;
	JSONArray features;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_features);
		features_gallery = (CircleGallery) findViewById(R.id.features_gallery);
		features = ASSET.loadJSONs("features.json");
		List<String> titles = new ArrayList<String>();
		List<Bitmap> images = new ArrayList<Bitmap>();
		for (int i = 0; i < features.length(); i++) {
			JSONObject feature = features.optJSONObject(i);
			titles.add(getString(getStringID(feature.optString("nameID"))));
			images.add(ASSET.loadImage(feature.optString("image"),true));
		}
		features_gallery.setData(titles.toArray(new String[titles.size()]), images.toArray(new Bitmap[images.size()]));
		features_gallery.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				JSONObject feature = features.optJSONObject(position);
				Intent intent = new Intent(FeaturesActivity.this, VideoPlayActivity.class);
				String url = "android.resource://" + getPackageName() + "/" + getRawID(feature.optString("video"));
				intent.putExtra("url",url);
				startActivity(intent);

			}
		});
	}

}
